package com.longe.netty.byteBuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class NettyByteBuf3 {

    public static void main(String[] args) {

        ByteBuf byteBuf = Unpooled.buffer(5);

        for (int i = 0; i < byteBuf.capacity(); i++) {
            byteBuf.writeByte(i + 1);
        }

        System.err.println("mark前的readerIndex = " + byteBuf.readerIndex());
        byteBuf.readByte();
        //标记此时的readerIndex
        byteBuf.markReaderIndex();
        System.err.println("mark后的readerIndex = " + byteBuf.readerIndex());
        System.err.println("---------------------------");
        byteBuf.resetReaderIndex(); //重新设置readerIndex为之前mark的地方
        System.err.println("resetReaderIndex后回到之前mark的地方, 此时readerIdx = " + byteBuf.readerIndex());
    }
}
